<script>
import { mapState } from 'vuex'
import { config, column, formatData } from './formConfig.js'
import BasicManage from '@/components/basic/BasicManage.vue'
import { requestApi } from '@/requset/api'
import { deepClone } from '@/plugins/clone'
export default {
    extends: BasicManage,
    data() {
        return {
            table_title: '算法模型组',
            url: 'model_group',
            baseForm: {
                name: '',
                value: '',
            },
            troubleList: [],
        }
    },
    computed: {
        ...mapState('backstage', ['backstageData', 'sensorType', 'wavcacq', 'sys_eig']),
    },
    methods: {
        getTrouble() {
            return requestApi('post', 'trouble/getlist', { page: 1, size: 9999 }).then((res) => {
                if (res.data.code == 0) {
                    this.troubleList = formatData(res.data.data)
                }
            })
        },
        add(data) {
            data.value = JSON.stringify(data.value)
            requestApi('post', this.url + '/add', this.to(deepClone(data))).then((res) => {
                if (res.data.code == 0) {
                    this.$message({
                        type: 'success',
                        message: '添加成功',
                    })
                    this.getlist()
                    this.$refs.zyform.closeDialog()
                }
            })
        },
        handleEdit(val) {
            let obj = deepClone(val)
            obj.value = JSON.parse(obj.value)
            this.BeforeEdit()
            this.dialog.title = '编辑' + this.table_title
            this.dialog.form = this.from(deepClone(obj))
            this.$refs.zyform.openDialog('change')
        },
        edit(data) {
            data.value = JSON.stringify(data.value)
            requestApi('post', this.url + '/edit', this.to(deepClone(data))).then((res) => {
                if (res.data.code == 0) {
                    this.$message({
                        type: 'success',
                        message: '编辑成功',
                    })
                    this.getlist()
                    this.$refs.zyform.closeDialog()
                }
            })
        },
    },
    created() {
        this.dialog.labelWidth = '100px'
        this.getTrouble().then(() => {
            config[1].options = this.troubleList
        })
        column[column.length - 1].buttons = [
            {
                text: '编辑',
                click: (val) => {
                    this.handleEdit(val)
                },
                icon: 'el-icon-edit',
            },
            {
                text: '删除',
                click: (val) => {
                    this.delete(val)
                },
                icon: 'el-icon-delete',
            },
        ]
        column[column.length - 1].if = this.operate
        this.dialog.config = config
        this.tableColumn = column
        this.getlist()
    },
}
</script>
